Socket
Socket
Sign inDemoInstall

@formatjs/intl-numberformat

Package Overview
Dependencies
Maintainers
3
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-numberformat

Ponyfill for ES2020 Intl.NumberFormat


Version published
Weekly downloads
325K
increased by1.26%
Maintainers
3
Weekly downloads
 
Created

What is @formatjs/intl-numberformat?

@formatjs/intl-numberformat is a JavaScript library that provides a robust and flexible way to format numbers according to different locales and formatting options. It leverages the ECMAScript Internationalization API (Intl) to offer a wide range of number formatting capabilities, including currency, percentages, and custom number formats.

What are @formatjs/intl-numberformat's main functionalities?

Basic Number Formatting

This feature allows you to format numbers according to a specified locale. In this example, the number 1234567.89 is formatted according to the 'en-US' locale.

const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US');
console.log(formatter.format(1234567.89)); // Output: 1,234,567.89

Currency Formatting

This feature allows you to format numbers as currency. In this example, the number 1234567.89 is formatted as USD currency according to the 'en-US' locale.

const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { style: 'currency', currency: 'USD' });
console.log(formatter.format(1234567.89)); // Output: $1,234,567.89

Percentage Formatting

This feature allows you to format numbers as percentages. In this example, the number 0.1234 is formatted as a percentage according to the 'en-US' locale.

const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { style: 'percent' });
console.log(formatter.format(0.1234)); // Output: 12%

Custom Number Formatting

This feature allows you to customize the number of fraction digits. In this example, the number 1234567.89 is formatted to always show two decimal places according to the 'en-US' locale.

const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
console.log(formatter.format(1234567.89)); // Output: 1,234,567.89

Other packages similar to @formatjs/intl-numberformat

Keywords

FAQs

Package last updated on 12 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc